package leetcode;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Leetcode491 {
    List<List<Integer>> res;
    List<Integer> list;
    public List<List<Integer>> findSubsequences(int[] nums) {
        this.res = new ArrayList<>();
        this.list = new ArrayList<>();
        dfs(nums,0);
        return res;
    }

    public void dfs(int[] nums,int index){
        if(list.size()>1){
            res.add(new ArrayList<>(list));
        }
        Set<Integer> s = new HashSet<>();//本层进行去重操作
        for(int i = index;i<nums.length;i++){
            if(list.size()>0&&nums[i]<list.get(list.size()-1)||s.contains(nums[i])){
                continue;
            }
            s.add(nums[i]);
            list.add(nums[i]);
            dfs(nums,i+1);
            list.remove(list.size()-1);
        }
    }
}
